package lc2;

import java.util.Arrays;

import org.junit.Test;

public class Ex2028 {

    class Solution {
        public int[] missingRolls(int[] rolls, int mean, int n) {
            int m = rolls.length;
            int sum = 0;
    
            for (int i = 0; i < m; i++) {
                sum += rolls[i];
            }
    
            int need = (m + n) * mean - sum;
    
            if (need < 1 * n || need > 6 * n) {
                return new int[0];
            }
    
            int[] res = new int[n];
            int mod = need / n;
            int cur = mod * n;
            int has = need - cur;
            Arrays.fill(res, mod);

            int idx = 0;
    
            while (has > 0) {
                res[idx++]++;
                has--;
            }
    
            return res;
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        int[] nums = new int[]{4,5,6,2,3,6,5,4,6,4,5,1,6,3,1,4,5,5,3,2,3,5,3,2,1,5,4,3,5,1,5};
        System.out.println(Arrays.toString(s.missingRolls(nums, 4, 40)));
    }
}
